<template>
	<van-goods-action>
		<!-- <van-goods-action-icon icon="chat-o" text="客服" @click="onClickIcon" /> -->
		<van-goods-action-icon icon="cart-o" text="购物车" @click="onClickIcon" />
		<!-- <van-goods-action-icon icon="shop-o" text="店铺" @click="onClickIcon" /> -->
		<van-goods-action-button type="warning" text="加入购物车" @click="onClickCar" />
		<van-goods-action-button type="danger" text="立即购买" @click="onClickButton" />
	</van-goods-action>
</template>

<script>
	import Vue from 'vue';
	import {
		GoodsAction,
		GoodsActionIcon,
		GoodsActionButton
	} from 'vant';

	Vue.use(GoodsAction);
	Vue.use(GoodsActionButton);
	Vue.use(GoodsActionIcon);
	import {
		Toast
	} from 'vant';

	export default {
		data() {
			return {
				g_count: '',
			}
		},
		props: {
			info: []
		},
		created() {
			this.$bus.$on('show', data => {
				this.g_count = data
			})
		},
		methods: {
			onClickIcon() {
				this.$router.push('/shopping')
			},
			onClickButton() {
				
				this.$http.get('/address/route').then(res=>{
					if(res.data.message=='token验证成功'){
						sessionStorage.setItem('goods',JSON.stringify({
							g_info:[{
								g_name:this.info.g_name,
								g_picture:this.info.g_picture,
								g_count:this.g_count,
								g_price:this.info.g_price,
								g_id:this.info.id
							}],
							u_id: this.$store.state.u_id
						}))
						this.$router.push('/Confirm')
					}else{
						Toast({
							message: '请先登录'
						});
						localStorage.clear()
						this.$router.push('/Login')
					}
				})
			},
			onClickCar() {
				
				//获取用户id
				// console.log(this.$store.state.u_id)
				// console.log(this.g_count)
				this.$http.post('/goodscar/goodscar', {
					g_name: this.info.g_name,
					g_picture: this.info.g_picture,
					g_price: this.info.g_price,
					g_count: this.g_count,
					g_id: this.info.id,
					u_id: this.$store.state.u_id
				}).then(res => {
					// console.log(res.data.message)
					if (res.data.message != 'token验证失败') {
						Toast({
							message: res.data.message
						});
					}else{
						Toast({
							message: '请先登录'
						});
						this.$router.push('/Login')
					}
					
				})
			},
		},
	};
</script>

<style>
</style>
